﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;
using ESRI.ArcGIS.Carto;

namespace MyGIS.Forms
{
    public partial class SaveForm : Form
    {
        public IRasterLayer SelectedLayer { get; private set; }

        public SaveForm(List<IRasterLayer> layers)
        {
            InitializeComponent();

            foreach (var layer in layers)
            {
                cmbLayers.Items.Add(new LayerItem(layer));
            }

            if (cmbLayers.Items.Count > 0)
            {
                cmbLayers.SelectedIndex = 0;
            }
        }

        private void btnOK_Click_1(object sender, EventArgs e)
        {
            if (cmbLayers.SelectedItem is LayerItem item)
            {
                SelectedLayer = item.Layer;
                DialogResult = DialogResult.OK;
                Close();
            }
        }


        private void btnCancel_Click_1(object sender, EventArgs e)
        {
            DialogResult = DialogResult.Cancel;
            Close();
        }

     
        private class LayerItem
        {
            public IRasterLayer Layer { get; }
            public string DisplayText => $"{Layer.Name} ({Layer.GetType().Name})";

            public LayerItem(IRasterLayer layer)
            {
                Layer = layer;
            }

            public override string ToString() => DisplayText;
        }

        private void cmbLayers_SelectedIndexChanged(object sender, EventArgs e)
        {

        }
    }
}